package weekMatch.one_346;

public class LeeCode_02 {
    public static void main(String[] args) {
        System.out.println(makeSmallestPalindrome("egcfe"));
    }
    private static String makeSmallestPalindrome(String s) {
        int n = s.length();
        StringBuilder sb = new StringBuilder(s);
        int l = 0, r = n - 1;
        while (l < r){
            char lc = sb.charAt(l);
            char rc = sb.charAt(r);
            if (lc == rc) {
                l++;
                r--;
                continue;
            }
            char mc = (char) Math.min(lc, rc);
            sb.replace(l, l + 1, mc + "");
            sb.replace(r, r + 1, mc + "");
            l++;
            r--;
        }
        return sb.toString();
    }
}
